﻿using System;
using System.Collections.Generic;

using System.Text;
using HZ.DrugTrade.Model;
using HZ.Common;
using System.Data;
using System.Data.SqlClient;
namespace HZ.DrugTrade.DAL
{
    /// <summary>
    /// 数据访问逻辑
    /// </summary>
    public class DAL_SelectArea
    {
        /// <summary>
        /// 条件查询
        /// </summary>
        /// <param name="where">查询用实体</param>
        /// <param name="currentPage">当前页</param>
        /// <param name="pageSize">每页显示记录数</param>
        /// <param name="totalRecord">（输出参数）总记录数目</param>
        /// <returns></returns>
        public static IList<SelectArea> GetCompanyByWhere(HZ.DrugTrade.Model.SelectArea query, int currentPage, int pageSize, out int totalRecord)
        {
            string where = HZ.DrugTrade.DAL2.DAL_Helper.GetWhereCondition<HZ.DrugTrade.Model.SelectArea>(query,true);

            HZ.Data.PageDescribe pdes = new HZ.Data.PageDescribe(string.Format("SELECT * FROM TB_SelectArea  WHERE 1=1 {0} ", where), pageSize);
            pdes.CurrentPage = currentPage;
            totalRecord = pdes.TotalCount;

            DataTable dt = pdes.GetSpecailPage();
            return HZ.Data.DAL_Helper.CommonFillList<HZ.DrugTrade.Model.SelectArea>(dt);
        }


        /// <summary>
        /// 增加
        /// </summary>
        /// <param name="selectArea"></param>
        /// <returns></returns>
        public static int AddSelectArea(HZ.DrugTrade.Model.SelectArea selectArea)
        {
             string strSql = string.Format(@"INSERT INTO TB_SelectArea
           (CompanyID_PS
           ,AreaIDs) VALUES
           ('{0}'
           ,'{1}')", selectArea.CompanyID_PS, selectArea.AreaIDs);
            return HZ.Data.DbHelperFactory.Create().ExecuteNonQuery(strSql);
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="selectArea"></param>
        /// <returns></returns>
        public static int UpdateSelectArea(HZ.DrugTrade.Model.SelectArea selectArea)
        {
            string strSql = string.Format(@"UPDATE TB_SelectArea
   SET AreaIDs ='{0}'
 WHERE CompanyID_PS = '{1}'", selectArea.AreaIDs, selectArea.CompanyID_PS);

            return HZ.Data.DbHelperFactory.Create().ExecuteNonQuery(strSql);
        }
    }
}
